home *** CD-ROM | disk | FTP | other *** search
- /*
- * File: MiscThreadedObject.h
- * Version: 1.0
- * Author: Steve Quirk
- * Summary: Provides basic threading mechanism to Object
- *
- * Revision History:
- * Nov 1994 steveq created
- *
- * Copyright 1994 Steve Quirk steveq@telerate.com
- *
- * A threaded object can run in it's own thread. Simply send a
- * runInNewThread message to the instance & a thread will be created
- * and the instance's 'run' method will be invoked. The thread will
- * be destroyed when the run method returns.
- * To be useful, a subclass must override the run method - this
- * implementation simply returns self.
- *
- * By default, the instance is sent a 'free' message after the 'run' method
- * returns. Override this behaviour by sending 'freeAfterRun:NO'. Of course,
- * don't call 'free' until after run returns.
- *
- * To aid debugging, the name of the thread will be whatever is returned
- * by [self name]. Override -name if you want to customize that.
- *
- */
- #import <objc/Object.h>
- #import <mach/cthreads.h>
- #import <mach/thread_info.h>
-
- @interface MiscThreadedObject:Object
- {
- cthread_t objThread;
- thread_info_t info;
- thread_info_t schedInfo;
- BOOL freeOnReturnFromRun; /* default = YES */
- }
- /*
- * get/set thread count limit for task
- */
- + (int)getThreadLimit;
- + (void)setThreadLimit:(int)newLimit;
- + (int)errno;
-
- - (BOOL)freeAfterRun;
- - freeAfterRun:(BOOL)yesOrNo; /* NO => keep object after thread exits */
-
- /*
- * run methods:
- */
- - run; /* override this to do something useful */
- - runInNewThread; /* spawns new thread (which calls run) & returns self */
- - fork; /* spawns new thread but doesn't detach */
- - (any_t)join; /* suspends caller until receiver exits thread */
-
- - (thread_info_t)threadInfo; /* returns basic thread information */
- - (thread_info_t)threadSchedInfo; /* returns scheduling thread information */
-
- /*
- * suspend/resume a thread:
- */
- - suspend; /* suspend's the receiver's thread */
- - resume; /* undoes a suspend */
- - abort; /* aborts a system call the receiver may be executing */
- - switchTo; /* causes a context switch into the receivers thread */
-
- @end
-